package com.hedl.practice.diyJava.gather.study_deque.test;

import java.util.Deque;
import java.util.LinkedList;

public class StudyDeque {
    public static void main(String[] args) {

        Deque<String> deque = new LinkedList<>();

        deque.offerLast("A");       //A
        deque.offerFirst("B");      //B-A
        deque.offerLast("C");       //B-A-C
        deque.offerFirst("D");      //D-B-A-C
        deque.offerLast("E");       //D-B-A-C-E
        deque.offerFirst("F");      //F-D-B-A-C-E
        deque.offerLast("G");       //F-D-B-A-C-E-G
        deque.offerFirst("H");      //H-F-D-B-A-C-E-G
        System.out.println(deque);      //H-F-D-B-A-C-E-G

        deque.removeFirst();        //删除队首
        System.out.println(deque);      //F-D-B-A-C-E-G
        deque.removeLast();     //删除队尾
        System.out.println(deque);      //F-D-B-A-C-E

        deque.pollFirst();     //获取队首元素并删除
        System.out.println(deque);      //D-B-A-C-E
        deque.pollLast();           //获取队尾元素并删除
        System.out.println(deque);      //D-B-A-C

        deque.peekFirst();      //获取队首元素不删除      D
        System.out.println(deque);      //D-B-A-C
        deque.peekLast();       //获取队尾元素不删除     C
        System.out.println(deque);      //D-B-A-C
        System.out.println(deque.getFirst());       //获取队首元素        D
        System.out.println(deque.getLast());        //获取队尾元素        C


    }
}
